#include <iostream>
#include <iterator>
#include <vector>
#include <unordered_map>
#include <string>

#include <type_traits>
#include <functional>

template<typename It>
void doWhatIMean(It b, It e) {
    while (b != e) {
        //typename std::iterator_traits<It>::value_type value = *b;
        auto value = *b;

        std::cout << ++value << std::endl;
        b++;
    }
}

class Key {
public:
    std::string K;

public:
    Key(const std::string& ok) : 
        K(ok){}

    Key(const Key& key) {
        K = key.K;
        std::cout << "Key Copy Construct" << std::endl;
    }

public:
    bool operator==(const Key& k) const {
        return K == k.K;
    }
};

int main() {
    std::vector<int> vi = {
        1, 2, 3, 4, 5
    };

    doWhatIMean(vi.begin(), vi.end());

    auto compareDigit = [](auto d1, auto d2){
        return d1 > d2;
    };

    compareDigit(1, 0);
    compareDigit(1.0, 1.5f);

    std::function<bool(int, int)> func = compareDigit;
    std::cout << "sizeof(compareDigit) : " << sizeof(compareDigit) << std::endl;
    std::cout << "sizeof(func) : " <<         sizeof(func) << std::endl;

    unsigned viSize1 = vi.size();
    auto viSize = vi.size();

    std::unordered_map<Key, int, std::function<std::size_t(const Key&)>> hashTable(
        100, 
        [](const Key& k){
            return std::hash<std::string>()(k.K);
        }
    );

    hashTable[Key("Hello")] = 0;
    hashTable[Key("World")] = 1;

    //类型声明错误引起拷贝
    for (const std::pair<Key, int>& pair : hashTable){
        std::cout << pair.first.K << std::endl;
    }

    for (const auto& pair : hashTable){
        std::cout << pair.first.K << std::endl;
    }

    int a = 0;
    //float& fa = a;

    const float& cfa = a;

    return 0;
}